home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / tool-inc.zip / WILDCARD.INC < prev   
Text File  |  1989-06-02  |  2KB  |  100 lines

  1.  
  2. (*
  3.  * Copyright 1987, 1989 Samuel H. Smith;  All rights reserved
  4.  *
  5.  * This is a component of the ProDoor System.
  6.  * Do not distribute modified versions without my permission.
  7.  * Do not remove or alter this notice or any other copyright notice.
  8.  * If you use this in your own program you must distribute source code.
  9.  * Do not use any of this in a commercial product.
  10.  *
  11.  *)
  12.  
  13. (*
  14.  * Wildcard match function
  15.  *
  16.  * S.H.Smith, rev. 04-Oct-87
  17.  *
  18.  *)
  19.  
  20. function wildcard_match(keyword,line:  anystring): boolean;
  21. var
  22.    keypos,linpos:  integer;
  23.  
  24. begin
  25.    if keyword = '*.*' then
  26.    begin
  27.       wildcard_match := true;
  28.       exit;
  29.    end;
  30.  
  31. (**
  32. if setdebug then
  33. writeln(dbfd,'match key=',keyword,' line=',line);
  34. **)
  35.    keypos := 1;
  36.    linpos := 1;
  37.  
  38.    (* do a "wildcard" filename scan *)
  39.    while true do
  40.    begin
  41.  
  42.       (* end of keyword?  we might have a match if so *)
  43.       if keypos > length(keyword) then
  44.       begin
  45.          wildcard_match := (linpos >= length(line)) or (line[linpos] = ' ');
  46. (**
  47. if setdebug then
  48. writeln(dbfd,'match=',(linpos >= length(line)) or (line[linpos] = ' '));
  49. **)
  50.          exit;
  51.       end
  52.       else
  53.  
  54.       (* end of line?  we missed a match if so *)
  55.       if linpos > length(line) then
  56.       begin
  57.          wildcard_match := false;
  58. (**
  59. if setdebug then
  60. writeln(dbfd,'no1');
  61. **)
  62.          exit;
  63.       end
  64.       else
  65.  
  66.       (* does line match keyword? (? matches anything); step forward if so *)
  67.       if (keyword[keypos] = upcase(line[linpos])) or 
  68.          (keyword[keypos] = '?') then
  69.       begin
  70.          inc(keypos);
  71.          inc(linpos);
  72.       end
  73.       else
  74.  
  75.       (* is keyword a *?  skip to . or end if so *)
  76.       if keyword[keypos] = '*' then
  77.       begin
  78.          while (line[linpos]<>' ') and (line[linpos]<>'.') and
  79.                (linpos < length(line)) do
  80.             inc(linpos);
  81.  
  82.          inc(keypos);
  83.       end
  84.       else
  85.  
  86.       (* else no match is possible; terminate scan *)
  87.       begin
  88.          wildcard_match := false;
  89. (**
  90. if setdebug then
  91. writeln(dbfd,'no1');
  92. **)
  93.          exit;
  94.       end;
  95.    end;
  96.  
  97. end;
  98.  
  99.  
  100.